473,468 Members | 1,906 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamically update DropDownList with new value

32 New Member
i am developing a web page in that i have a drop down list for Authors Name...which allows to select the Author available in the data source.and if the user wants a new author to insert into the authors table i had put a add new button beside the drop down list will allows the user to add the details of the new authors...so soon the user will select the add new button the Author page will be get open to enter Author details.....and now my requirement is soon the user click the insert button in Authors page...the Author details page should close and the newly entered Author name in the Author page should be added into drop down list of Books page with out refreshing.. can any one plz solve my problem plz. im developing my web page using asp.in with c#....
and im using following JS in .cs file
this.RegisterClientScriptBlock("newAuthor", "<script language='JavaScript'> newAuthors('"+ddlAuthors.DataTextField+"','"+ddlAu thors.DataValueField+"','"+ddlAuthors.ClientID+"') </script>");

hope i will get a quick respone

thank u...
Jan 5 '09 #1
8 10643
Frinavale
9,735 Recognized Expert Moderator Expert
You can use JavaScript to add the author to the DropDownList but you may run into problems because the ViewState won't match with what was sent to the browser. For an idea of what's involved to get this to work, check out this thread...I know it deals with ListBoxes but the same concept will apply to your DropDownList.

It would be easier to just make an asynchronous call to the server to refresh just the DropDownList instead of the whole page.
Jan 5 '09 #2
satyabhaskar
32 New Member
hi boos,
Thanks for reply, iam in idea to write the same code for java script in authors page...but the drop down list is in books page ... how can i get the id of the drop down list which is in Books page into the Authors page...
will u plz make me clear in this ...
thanks
Jan 6 '09 #3
Frinavale
9,735 Recognized Expert Moderator Expert
I'm assuming that you are using popups. The key to this is to use the JavaScript window.opener to retrieve a reference to the Parent window. You have to set the name of the parent window before opening the popup window so that the window.opener will be set.

So, make a JavaScript function that opens the popup window but names the parent window before opening it. Also, create a function that updates the list that accepts a parameter with the value to add to it.

Call the function that opens the child window when you click the Add button...and when you hit "update" in the child window, have the update button refer to the windows.opener to call the JavaScript function that updates the list....passing it the value to add to the list.

Look up how to use window.opener to achieve what you're trying to accomplish.

-Frinny
Jan 6 '09 #4
satyabhaskar
32 New Member
hey thanks boss... ur reply helped me a lot... i solved my problem by following ur reply....nw i got two problems one is linked to the previous problem..
1. soon im updating the Authors details if i press ok button available in that form i will be going back to books details.and nw the problem is im not able to display the authors name in dropdown list as my first choice visible which i added in the authors form. can i get the information or sample example for this problem...
i tried even setting selectedIndex=1 and 0 but its not solved..

2. i have some number of text boxes in my page and even a button... soon i enter text in first text box and press enter it actually fires the button...but i dont to be like that...my need is soon i press enter the text in the text box and press enter i want to focus on the cursor on the next text box so that user can type the info in next text box(similar like tab key)...so actually i want navigation to carriage return..can u plz make me clear even in this doubt..by giving some relevant example.. so that i can take further steps in my project...

thanks
Jan 7 '09 #5
Frinavale
9,735 Recognized Expert Moderator Expert
@satyabhaskar
In JavaScript you cannot set the DropDownList.SelectedIndex=1.
The reason you can't do this is because a DropDownList is an ASP.NET Object...not a JavaScript Object. ASP.NET transforms DropDownLists into HTML in order to let the browser know how to display them. The HTML generated for a DropDownList is a <select>.

Since you aren't posting back to the server to process this information using .NET, and you are certain that you want to use JavaScript to implement your solution, I have moved your question to the JavaScript Forum where JavaScript experts can help you. (It would be very challenging for any .NET expert to help you with this)


@satyabhaskar
This is a new question.
You should post this question in a new thread in the JavaScript Forum. I would recommend that you research and attempt this before asking your question because there is a lot of information and tutorials on the web about how to do this.
Jan 7 '09 #6
acoder
16,027 Recognized Expert Moderator MVP
@satyabhaskar
Get the client-side generated ID and use document.getElementById() to refer to the element and then set it's selectedIndex property.
Jan 9 '09 #7
Frinavale
9,735 Recognized Expert Moderator Expert
@acoder

Since this ID is not dynamically generated (because you're updating the list using JavaScript) you should know what it is .
Jan 9 '09 #8
acoder
16,027 Recognized Expert Moderator MVP
To avoid confusion and see exactly what the problem is, satyabaskhar, post your code.
Jan 10 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
3
by: Kevin Pedersen | last post by:
Hello, I am using an editable datagrid. After I save the changes the datagrid shows the old values. I've read the posts about the Page_Load and not binding the datagrid each time. The SQL that...
2
by: Ron | last post by:
Hello, I am trying to create a page that pulls class rosters from an SQLServer database. The roster table definition is: emp_id(pk, fk), sec_id(pk, fk), reg_date and reg_status. Status can be...
2
by: Dave | last post by:
Hi, I'm building a maintenance form for a table and some of the fields are textboxes (i.e name) and some should be dropdowns (i.e country of origin) When a user clicks 'Edit' in the...
4
by: Shiju Poyilil | last post by:
Hello EveryBody, I have a dropdownlist with some values as .net server controls & a button , on clicking a button i need to generate the choosen contorl dynamically. I am giving a small glimpse...
5
by: Amelyan | last post by:
How can I get state of dynamically created controls (RadioButton, CheckBox, TextBox.Text) on post back when I click submit button? The only way I know is by traversing Response.Form enumberator;...
0
by: Zark3 | last post by:
Hi all, In a web form I use a for loop to dynamically add TextBox'es to a page (one for each item in an input file). I can get the input values and I can display them in Label's and TextBox'es....
3
by: J055 | last post by:
Hi I have a PlaceHolder control inside a FormView EditItemTemplate: <asp:PlaceHolder ID="phResponseText" runat="server"> <tr> <td> <asp:Label ID="lblResponseText"...
4
by: imranabdulaziz | last post by:
Dear All, I am using asp.net2.0, C#, sql2005 using Visual studio 2005 Let Me explain the scenario I have checkboxlist containg 15 field. Based on no of checked field . I created...
2
by: mylog | last post by:
Hi I am having a problem of getting the value from the dynamically generated table and dropdownlist. What I am facing is, I have created a table in the aspx page and now I need to add values to...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.